﻿#ifndef COMMON_H
#define COMMON_H
#include <QDebug>
#include <QThread>
#include "halconcpp/HalconCpp.h"
#include "ui_mainwindow.h"
#include <string.h>
#include "CameraApi.h"


const int PLCSUCCEED = 0;
const int PLCDBNUMBER = 3;
const int PLCRACK = 0;
const int PLCSLOT = 1;

namespace Ui {
class MainWindow;
//class PlcDlg;
}

typedef struct _WIDTH_HEIGHT {
	int     display_width;
	int     display_height;
	int     xOffsetFOV;
	int     yOffsetFOV;
	int     sensor_width;
	int     sensor_height;
	int     buffer_size;
}Width_Height;

struct CameraInfo
{
	//SDK
	//设备句柄
	CameraHandle g_hCamera = -1;
	unsigned char* g_pRawBuffer = NULL;     //raw数据
	unsigned char* g_pRgbBuffer = NULL;     //处理后数据缓存区
	tSdkFrameHead           g_tFrameHead;       //图像帧头信息
	tSdkCameraCapbility     g_tCapability;      //设备描述信息

	BYTE* g_readBuf = NULL;//画板显示数据区

	int g_read_fps = 0;//统计读取帧率
	int g_disply_fps = 0;//统计显示帧率

	int g_SaveParameter_num = 0;//保存参数组   
	int g_SaveImage_type = 0;  //保存图像格式
	Width_Height g_W_H_INFO;//显示画板到大小和图像大小
};


struct CameraData
{
    int m_nIndex;                           //编号
    QString qStrCameraID;
    HalconCpp::HTuple hv_WindowHandle;
    HalconCpp::HObject Hobj;
    int m_nNGorOK;

};


// PLC PLCdlg
struct PlcInfo{
    int nAddress = 0;
    int nValue = 0;
};

// Caemra
struct CameraParameter
{
    double ExposureTimeAbs;
    int OffsetX;
    int OffsetY;
    int Height;
    int Width;
};

struct CameraDlgInfo
{
    int m_nFunction;                    // 0.无 1.打开相机获取相机值 2.启动硬触发 3.启动连续采集 4.保存相机数据
    int m_nCamera;                      // 相机编号
    HalconCpp::HTuple hv_WindowHandle;  // 绑定的 Halcon 控件值
    bool m_bOpen;                       // 是否打开 Halcon 窗口
    int m_nSingle;                      // 单张硬触发
    int m_nConsecutive;                 // 连续采集
    int m_nPlate;                       // 是否启动转盘
    CameraParameter m_nParameter;       // 相机参数
};

// 存图   0  不存图   1 存图
struct SW_SaveImg{
    int nSwPic = 0;
    int nSwNg = 0;
    int nCCD1 = 0;
    int nCCD2 = 0;
    int nCCD3 = 0;
    int nCCD4 = 0;
    int nCCD5 = 0;
    int nCCD6 = 0;
    int nCCD7 = 0;
    int nCCD8 = 0;
};

// 测量   0 不测量    1 测量
struct SW_Check{
    int nCCD1 = 1;
    int nCCD2 = 1;
    int nCCD3 = 1;
    int nCCD4 = 1;
    int nCCD5 = 1;
    int nCCD6 = 1;
    int nCCD7 = 1;
    int nCCD8 = 1;
};


// 0 不选择 1 选择
struct SW_AlgPart
{
    int nCCD = 0;
    int nAlgA = 0;
    int nAlgB = 0;
    int nDefect = 0;
    int nRect = 0;
};

// 缺陷类型
struct SW_Alg
{
    SW_AlgPart m_ccd1;
    SW_AlgPart m_ccd2;
    SW_AlgPart m_ccd3;
    SW_AlgPart m_ccd4;
    SW_AlgPart m_ccd5;
    SW_AlgPart m_ccd6;
    SW_AlgPart m_ccd7;
    SW_AlgPart m_ccd8;
};
// 宽度  长度   角度1 ~ 4

struct M_R_DataA{
    float dWidth = 0;
    float dWidthPa = 0;
    float dLength = 0;
    float dLengthPa = 0;

    float dAngle1 = 0;
    float dAngle2 = 0;
    float dAngle3 = 0;
    float dAngle4 = 0;
};

struct M_R_IMPURITY{
    int parameter1 = 0;
    int parameter2 = 0;
    int parameter3 = 0;
    int parameter4 = 0;
    int parameter5 = 0;
    int parameter6 = 0;
    int parameter7 = 0;
    int parameter8 = 0;
    int parameter9 = 0;
    int parameter10 = 0;
};



// 厚度  厚度平行度
struct M_R_DataB{
    float dThickness = 0;
    float dThicknessPa = 0;
};

// 0 高度   1平行度  2 左斜边角度   3  右斜边角度
struct M_T_DataA
{
    float dHeight = 0;
    float dHeightPa = 0;
    float dLefthy = 0;
    float dRighthy = 0;
};
//  高度  宽度
struct M_TS_DataA
{
    float dHeight = 0;
    float dWidth = 0;
};
// 厚度
struct M_TSS_DataA
{
    float dThickness = 0;
};
// 弧边1长度  弧边2长度  直边3长度  直边4长度  中直长度 轮廓度
struct M_Se_DataA
{
    float dEdge1 = 0;
    float dEdge2 = 0;
    float dStraight3 = 0;
    float dStraight4 = 0;
    float dMStraight = 0;
    float dProfile = 0;
};

//宽度  长度  角度1  角度2
struct M_Bullet_DataA{
    float dWidth = 0;
    float dLength = 0;
    float dAngle1 = 0;
    float dAngle2 = 0;
};


// 缺陷
// 方形
struct D_R_DataA{
    float dInterior = 0;
    float dExternal = 0;
};

// 扇形
struct D_S_DataA{
    float dInterior = 0;
    float dExternal = 0;
};

// 计数
struct M_NUMBER
{
    M_R_DataA dM_R_DataA;
    M_R_DataB dM_R_DataB;
    M_T_DataA dM_T_DataA;
    M_TS_DataA dM_TS_DataA;
    M_TSS_DataA dM_TSS_DataA;
    M_Se_DataA dM_Se_DataA;
    M_Bullet_DataA dM_Bullet_DataA;
    D_R_DataA dD_R_DataA;
    D_S_DataA dD_S_DataA;
};


struct ALG_PLACE
{
    HalconCpp::HTuple x1 = 0;
    HalconCpp::HTuple y1 = 0;
    HalconCpp::HTuple x2 = 0;
    HalconCpp::HTuple y2 = 0;
};

struct CCD_ALG_PLACE
{
    ALG_PLACE cd1;
    ALG_PLACE cd2;
    ALG_PLACE cd3;
    ALG_PLACE cd4;
};
//检测开始时间,检测结束时间,产品类型,产品批次,产品名,产品规格,初始数量,结束数量,良品数,良品率,不良数,不良率,尺寸不合格数,缺陷不合格数,混料,异常
struct CsvData
{
    QString csStarTime;
    QString csStopTime;
    QString csType;
    QString csIndex;
    QString csName;
    QString csSize;
    QString csStarNum;
    QString csStopNum;
    QString csGodNum;
    QString csGodRatio;
    QString csBadNum;
    QString csBadRatio;
    QString csNG1;
    QString csNG2;
    QString csNG3;
    QString csNG4;

    QString csNum1;
    QString csNum2;
    QString csNum3;
    QString csNum4;
    QString csNum5;
    QString csNum6;
    QString csNum7;
    QString csNum8;
    QString csNum9;
    QString csNum10;
    QString csNum11;
    QString csNum12;

    QString csNum1Up;
    QString csNum1UpRatio;
    QString csNum1Down;
    QString csNum1DownRatio;
    QString csNum1Unknown;

    QString csNum2Up;
    QString csNum2UpRatio;
    QString csNum2Down;
    QString csNum2DownRatio;
    QString csNum2Unknown;

    QString csNum3Up;
    QString csNum3UpRatio;
    QString csNum3Down;
    QString csNum3DownRatio;
    QString csNum3Unknown;


    QString csNum4Up;
    QString csNum4UpRatio;
    QString csNum4Down;
    QString csNum4DownRatio;
    QString csNum4Unknown;

    QString csNum5Up;
    QString csNum5UpRatio;
    QString csNum5Down;
    QString csNum5DownRatio;
    QString csNum5Unknown;

    QString csNum6Up;
    QString csNum6UpRatio;
    QString csNum6Down;
    QString csNum6DownRatio;
    QString csNum6Unknown;



    QString csAngle1OK;
    QString csAngle1NG;
    QString csAngle1Up;
    QString csAngle1UpRatio;
    QString csAngle1Down;
    QString csAngle1DownRatio;
    QString csAngle1Unknown;

    QString csAngle2OK;
    QString csAngle2NG;
    QString csAngle2Up;
    QString csAngle2UpRatio;
    QString csAngle2Down;
    QString csAngle2DownRatio;
    QString csAngle2Unknown;


    QString csAngle3OK;
    QString csAngle3NG;
    QString csAngle3Up;
    QString csAngle3UpRatio;
    QString csAngle3Down;
    QString csAngle3DownRatio;
    QString csAngle3Unknown;

    QString csAngle4OK;
    QString csAngle4NG;
    QString csAngle4Up;
    QString csAngle4UpRatio;
    QString csAngle4Down;
    QString csAngle4DownRatio;
    QString csAngle4Unknown;

};

struct UserData
{
    int nId;
    QString strName;
    int nLevel;
};

#endif // COMMON_H
